<?php
declare (strict_types=1);

namespace app\dao\adv;

use app\dao\BaseDao;
use app\model\adv\AdvList;
use think\db\exception\{DataNotFoundException, DbException, ModelNotFoundException};

/**
 *
 * Class AdvListDao
 * @package app\dao\adv
 * @mixin AdvList
 */
class AdvListDao extends BaseDao
{

    /**
     * 设置模型
     * @return string
     */
    protected function setModel(): string
    {
        return AdvList::class;
    }

    /**
     * @param array $whereData
     * @param int $page
     * @param int $limit
     * @param array $with
     * @return array
     * @throws DbException
     */
    public function getAdvList(array $whereData, int $page, int $limit, array $with = ['adv']): array
    {
        return AdvList::with($with)
            ->withSearch(array_keys($whereData), $whereData)
            ->order('sort')
            ->paginate([
                'list_rows' => $limit,
                'var_page' => 'page'
            ])->each(function ($item, $key) {
                $item['imgList'] = $item->imgList;
                return $item;
            })
            ->toArray();
    }
}
